
/* 
 * This file is part of FreeBMS - an open source battery management system
 *
 * Structure Headers
 * 
 * NOTE: This code is designed to be compiled using SOURCEBOOST (http://www.sourceboost.com)
 */
 
/* This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
#ifndef _STRUCT_H_
#define _STRUCT_H_

#include "types.h"

// Cell record data structure 
struct cell_data {
	struct cell_data *next; 	// Next cell in list
	unsigned int voltage;   	// Current voltage of cell
	BYTE id;                	// ID of chip for record
	BYTE shunting;          	// Whether or not cell is shunting
	BYTE comm_errors;			// Communication errors with chip
	BYTE cell_errors;			// Number of cell ADC errors
};

// Message record data structure
struct mesg_data {
	struct mesg_data *next; 	// Next message in list
	unsigned short mesg_id;		// Message ID
	BYTE type;					// Type of message (CAN / Serial)
	BYTE rxblock;				// Block for receive
	BYTE dest;					// Destination for message
	BYTE length;				// Length of message
	BYTE data[8];				// Message data buffer
};

// Global defines
#define MESG_SERIAL			0	// Serial message datatype
#define MESG_CANBUS			1	// CANBUS message datatype

// External variables
extern struct cell_data *first_cell;
extern struct mesg_data *first_mesg;

// Function prototypes
struct cell_data *update_voltage(BYTE id, BYTE shunting, unsigned int volt);
struct cell_data *update_shunting(BYTE id, BYTE shunt);
struct cell_data *insert_cell(BYTE id, BYTE shunting, unsigned int volt);
struct cell_data *find_cell(BYTE id);
struct mesg_data *insert_mesg(BYTE type, unsigned short mesg_id, BYTE dest, BYTE rxblock, BYTE length, BYTE *buffer);

#endif // _STRUCT_H_
